﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GraphicsEditor.Other
{
    enum histogramView { red, blue, green, all };
    public partial class HistogramForm : Form
    {
        
        Histogram histogram;
        histogramView view = histogramView.all;
        public HistogramForm(Image image)
        {
            InitializeComponent();
            ResizeRedraw = true;
            BackColor = Color.White;
            histogram = new Histogram(new Bitmap(image));
        }

        private void HistogramForm_Paint(object sender, PaintEventArgs e)
        {
            //e.Graphics.DrawImage(histogram.image, this.DisplayRectangle);
            List<int> values;
            Color color;
            switch (view)
            {
                case histogramView.red:
                    values = histogram.redValues;
                    color = Color.Red;
                    break;
                case histogramView.blue:
                    values = histogram.blueValues;
                    color = Color.Blue;
                    break;
                case histogramView.green:
                    values = histogram.greenValues;
                    color = Color.Green;
                    break;
                default:
                    values = histogram.allValues;
                    color = Color.Black;
                    break;
            }

            histogram.drawHistogram(e.Graphics, this.Bounds, color, values);
        }

        private void redToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            view = histogramView.red;
            this.Invalidate();
        }

        private void greenToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            view = histogramView.green;
            this.Invalidate();
        }

        private void blueToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            view = histogramView.blue;
            this.Invalidate();
        }

        private void overallToolStripMenuItem_Click(object sender, EventArgs e)
        {
            view = histogramView.all;
            this.Invalidate();
        }
    }
}
